package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.OrderLink;
import com.ruoyi.system.domain.vo.OperationTreeVo;
import com.ruoyi.system.service.IOrderLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单环节管理Controller
 * 
 * @author ruoyi
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/link")
public class OrderLinkController extends BaseController
{
    @Autowired
    private IOrderLinkService orderLinkService;

    /**
     * 环节全量下拉数据
     */
    @RequiresPermissions("order:link:allList")
    @GetMapping("/allList")
    public AjaxResult allList()
    {
        List<OrderLink> list = orderLinkService.selectAllList();
        return success(list);
    }

    /**
     * 查询订单环节管理列表
     */
    @RequiresPermissions("order:link:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderLink orderLink)
    {
        startPage();
        List<OrderLink> list = orderLinkService.selectOrderLinkList(orderLink);
        return getDataTable(list);
    }

    /**
     * 我的待办
     *
     * @return AjaxResult
     */
    @RequiresPermissions("order:link:dropDown")
    @Log(title = "员工环节权限", businessType = BusinessType.OTHER)
    @GetMapping("/dropDown")
    public AjaxResult dropDown(String nameOrOrderId)
    {
        List<OperationTreeVo> list = orderLinkService.dropDown(nameOrOrderId);
        return success(list);
    }

    /**
     * 导出订单环节管理列表
     */
    @RequiresPermissions("order:link:export")
    @Log(title = "订单环节管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderLink orderLink)
    {
        List<OrderLink> list = orderLinkService.selectOrderLinkList(orderLink);
        ExcelUtil<OrderLink> util = new ExcelUtil<OrderLink>(OrderLink.class);
        util.exportExcel(response, list, "订单环节管理数据");
    }

    /**
     * 获取订单环节管理详细信息
     */
    @RequiresPermissions("order:link:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderLinkService.selectOrderLinkById(id));
    }

    /**
     * 新增订单环节管理
     */
    @RequiresPermissions("order:link:add")
    @Log(title = "订单环节管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderLink orderLink)
    {
        return toAjax(orderLinkService.insertOrderLink(orderLink));
    }

    /**
     * 修改订单环节管理
     */
    @RequiresPermissions("order:link:edit")
    @Log(title = "订单环节管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderLink orderLink)
    {
        return toAjax(orderLinkService.updateOrderLink(orderLink));
    }

    /**
     * 删除订单环节管理
     */
    @RequiresPermissions("order:link:remove")
    @Log(title = "订单环节管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderLinkService.deleteOrderLinkByIds(ids));
    }
}
